import { TypeOrmModuleOptions } from "@nestjs/typeorm"
import * as process from "process"

/**
 * Database configuration file
 */
export async function databaseConfig(): Promise<TypeOrmModuleOptions> {
  return {
    type: "mysql",
    host: "localhost",
    port: 3306,
    database: process.env["DATABASE_NAME"],
    username: process.env["DATABASE_USERNAME"],
    password: process.env["DATABASE_PASSWORD"],
    retryAttempts: 10, // The number of reconnection attempts if database fails when starting the project
    retryDelay: 1000, // Reconnection interval, in milliseconds
    synchronize: true, // Do you compare the differences between the database structure and entity classes when starting the project and update them
    autoLoadEntities: true // Automatically load entity classes
  }
}
